using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using UnityEngine.UI;

namespace AsterroidX
{
    public class UIPowerUps : MonoBehaviour
    {

        public Dictionary<string,UIPowerUp>ActivePowerUps=new Dictionary<string, UIPowerUp>();
        public void AddPowerUp(string powerUpName,UIPowerUp powerUp,Sprite sprite,float seconds,Action onPowerEnd)
        {

            if(ActivePowerUps.ContainsKey(powerUpName))
            {
                var powerUpUI= ActivePowerUps[powerUpName];

                powerUpUI.OnEnd = onPowerEnd;

                powerUpUI.Seconds += seconds;
            }
            else
            {
                var powerUpUI = powerUp.InstantiateWithParent(this);

                powerUpUI.UIPowerUps = this;
               

                    powerUpUI.PowerUpName = powerUpName;

                powerUpUI.Seconds = seconds;
                powerUpUI.OnEnd = onPowerEnd;
                var powerUpSpreadImage = powerUpUI.GetComponent<Image>();
                powerUpSpreadImage.sprite = sprite;
                powerUpUI.transform.Find("Seconds").GetComponent<Text>().text = seconds.ToString("NO");
                powerUpUI.Show();
               
                ActivePowerUps.Add(powerUpName, powerUpUI);
            }

        }

        public void Remove(string powerUpName)
        {
            ActivePowerUps.Remove(powerUpName);
        }
    }
}

